package com.idrem.data.url;

import java.util.HashMap;

import com.idrem.util.StringUtil;

public class UrlGenerator {
	

	
	public static String getShopUrl(HashMap<String, String> paramValue) {
		String[] params = {UrlParamsKey.TYPE, UrlParamsKey.USERNAME };
		return UrlName.SHOP_URL + genParamStr(paramValue, params);
	}
	
	public static String getProductUrl(HashMap<String, String> paramValue) {
		String[] params = {UrlParamsKey.TYPE, UrlParamsKey.USERNAME };
		return UrlName.PROD_URL + genParamStr(paramValue, params);
	}
	
	public static String getKPIUrl(HashMap<String, String> paramValue) {
		String[] params = {UrlParamsKey.TYPE, UrlParamsKey.USERNAME };
		return UrlName.KPI_URL + genParamStr(paramValue, params);
	}
	
	public static String getConstantUrl(HashMap<String, String> paramValue) {
		String[] params = {UrlParamsKey.TYPE, UrlParamsKey.USERNAME };
		return UrlName.CONSTANT_URL + genParamStr(paramValue, params);
	}
	
	

	private static String genParamStr(HashMap<String, String> paramValue, String[] params) {
		
		int guard = 0;
		StringBuffer urlParam = new StringBuffer();

		urlParam.append("?");

		for (String param : params) {
			if (guard > 0) {
				urlParam.append("&");
			}
			urlParam.append(param);
			urlParam.append("=");
			urlParam.append(StringUtil.toString(paramValue.get(param), ""));

			guard++;
		}
		return urlParam.toString();
	}
	
	private static String genMultiParamStr(HashMap<String, String> paramValue) {
		
		StringBuffer urlParam = new StringBuffer();
		urlParam.append("?");
		
		urlParam.append(UrlParamsKey.PRODUCT);
		urlParam.append("=");
		urlParam.append(StringUtil.toString(paramValue.get(UrlParamsKey.PRODUCT), ""));
		
		urlParam.append("&");
		urlParam.append(paramValue.get("key"));
		
		return urlParam.toString();
	}
}
